using UnityEngine;

public class RespawnableFallingObject : FallingObjectBehaviour
{
	public const float DELAY_TO_RESPAWN = 30f;

	private Vector3 _savedPosition;

	private Quaternion _savedRotation;

	private void Start()
	{
		_savedPosition = base.transform.position;
		_savedRotation = base.transform.rotation;
	}

	public override void DisableObject()
	{
		if (!_isDestroyed)
		{
			_isDestroyed = true;
			_gameManager.ProcessCapture(this, _holeId);
			Invoke("DestroyObject", 3f);
		}
	}

	public override void ForceDisableObject()
	{
		if (!_isDestroyed)
		{
			_isDestroyed = true;
			_gameManager.ProcessCapture(this, _holeId);
			DestroyObject();
		}
	}

	private void DestroyObject()
	{
		Invoke("Respawn", 30f);
	}

	private void Respawn()
	{
		_isDestroyed = false;
		_cachedTransform.localPosition = _savedPosition;
		_cachedTransform.localRotation = _savedRotation;
		Rigidbody componentInChildren = GetComponentInChildren<Rigidbody>();
		if ((bool)componentInChildren)
		{
			componentInChildren.velocity = Vector3.zero;
			componentInChildren.angularVelocity = Vector3.zero;
		}
	}
}
